package org.example.lease.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import org.example.lease.model.entities.CityInfo;
import org.example.lease.model.entities.DistrictInfo;
import org.example.lease.model.entities.ProvinceInfo;
import org.example.lease.model.result.Result;
import org.example.lease.service.CityInfoService;
import org.example.lease.service.DistrictInfoService;
import org.example.lease.service.ProvinceInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/16 14:02
 */
@RestController
@Slf4j
@RequestMapping("/admin/region")
@Tag(name = "地区信息管理")
public class RegionInfoController {
    @Resource
    private CityInfoService cityInfoService;
    @Resource
    private ProvinceInfoService provinceInfoService;
    @Resource
    private DistrictInfoService districtInfoService;

    @Operation(summary = "查询省份列表")
    @GetMapping("/province/list")
    public Result<List<ProvinceInfo>> listProvince(){
        List<ProvinceInfo> list = provinceInfoService.list();
        return Result.ok(list);
    }

    @Operation(summary = "根据省份id查询城市信息")
    @GetMapping("/city/listByProvinceId")
    public Result<List<CityInfo>> listCity(@RequestParam Long id){
//        List<CityInfo> cityInfoList = cityInfoService.
//                list(Wrappers.lambdaQuery(CityInfo.class).eq(CityInfo::getProvinceId, id));
        List<CityInfo> cityInfoList = cityInfoService.lambdaQuery().eq(CityInfo::getProvinceId, id).list();
        return Result.ok(cityInfoList);
    }

    @Operation(summary = "根据城市id查询区域信息")
    @GetMapping("/district/listByCityId")
    public Result<List<DistrictInfo>> listDistrict(@RequestParam Long id){
        List<DistrictInfo> districtInfoList = districtInfoService.
                list(Wrappers.lambdaQuery(DistrictInfo.class).eq(DistrictInfo::getCityId, id));
        return Result.ok(districtInfoList);
    }

}
